'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
    async index() {
        const { ctx } = this;
        ctx.body = 'hi, egg';
    }
    //查询  分页
    async list(){
        let {ctx,service} = this;
        //1.pagenum 页码  pagenum  每页的条数 limit 
        //select * from list limit 起始下标,每页的条数
        let {pagenum=1,limit=5} = ctx.query;
        if(pagenum && limit){
            let list = await service.home.list(pagenum,limit);
            let total = await service.home.total();
            ctx.body = {
                code:1,
                data:list,
                total:total[0]['count(*)']
            }
        }else{
            ctx.body = {
                code:2,
                msg:'参数为空'
            }
        }
    }
}

module.exports = HomeController;
